{% extends 'layout.html' %}

{% block content %}
<div id="reportbro"></div>

<script type="text/javascript">

var rb = null;

function saveReport() {
    var report = rb.getReport();

	var report_type = '{{report_type}}';
	console.log(report_type)	
    var url= "../savev2/"+report_type		
	console.log(url)

	
    $.ajax(url, {
        data: JSON.stringify(report),
        type: "PUT", contentType: "application/json",
        success: function(data) {
            // report definition saved successfully,
            // set modified flag to false to disable save button
            rb.setModified(false);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            alert('saving report failed');
        }
    });
}

$(document).ready(function() {
    rb = $('#reportbro').reportBro({
        reportServerUrl: "{{ url_for('report.run') }}",
        saveCallback: saveReport
    });
    var report = {{report_definition|safe}};
    if (report) {
        rb.load(report);
    }
});
</script>
{% endblock %}
